﻿Imports BLL
Imports DAL
Public Class ClienteCAD
    Inherits System.Web.UI.Page
    Dim ObjBLL As New PessoaBLL
    Dim cod As Integer = 0
#Region "Métodos"
    Public Sub carrega()
        ObjBLL = New PessoaBLL(Val(cod))
        TCodigo.Text = objbll.Codigo
        TXTBairro.Text = ObjBLL.Bairro
        TXTCelular.Text = ObjBLL.Celular
        TXTTelefone.Text = ObjBLL.Telefone
        TXTCep.Text = ObjBLL.Cep
        TXTCidade.Text = ObjBLL.Cidade
        TXTNome.Text = ObjBLL.Nome
        TXTEndereco.Text = ObjBLL.Endereco
        TXTEmail.Text = ObjBLL.Email
        DDLUf.SelectedValue = ObjBLL.Uf
    End Sub
#End Region

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        cod = 0
        Dim conexao As New Conexao
        If (Not IsPostBack()) Then
            conexao.preencheCombo(DDLUf, "Mul_Uf", "uf_uf", "uf_uf", "", "")
            If Not IsNothing(Request("id")) Then
                cod = Val(Request("id"))
                BGravar.Text = "Alterar"
                carrega()
            End If
        End If
    End Sub

    Protected Sub BGravar_Click(sender As Object, e As EventArgs) Handles BGravar.Click
        Try
            ObjBLL = New PessoaBLL(Val(TCodigo.Text), TXTNome.Text, TXTTelefone.Text, TXTCelular.Text, TXTEmail.Text, TXTCep.Text, TXTEndereco.Text, TXTCidade.Text, DDLUf.SelectedValue, TXTBairro.Text)
            If (ObjBLL.InserirAlterar(Session("usu_nome"))) Then
                BGravar.Enabled = False
                LMSG.Text = "Gravado com Sucesso!"
                LMSG.Visible = True
            End If
        Catch ex As Exception
            LMSG.ForeColor = Drawing.Color.Red
            LMSG.Text = ex.Message
            LMSG.Visible = True
        End Try
    End Sub
End Class